package com.ls.uav_backend.model.enums;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum SensorTypeEnum {
    CONDUCTIVITY("电导率", "conductivity"),
    POTASSIUM("钾", "potassium"),
    NITROGEN("氮", "nitrogen"),
    PHOSPHORUS("磷", "phosphorus"),
    PH("PH", "PH"),
    MOISTURE("水分", "moisture"),
    INDOOR_TEMPERATURE("温度", "indoor_temperature");


    private final String text;

    private final String value;

    private static final Map<String, SensorTypeEnum> map = new HashMap<>();

    SensorTypeEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    static {
        for (SensorTypeEnum sensorTypeEnum : SensorTypeEnum.values()) {
            map.put(sensorTypeEnum.getValue(), sensorTypeEnum);
        }
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value 枚举值的value
     * @return 枚举值
     */
    public static SensorTypeEnum getEnumByValue(String value) {
        if (ObjUtil.isEmpty(value)) {
            return null;
        }
        return map.getOrDefault(value, null);
    }
}
